//
//  HEMyPrivatDoctorCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/9.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMyPrivatDoctorCell.h"

@interface HEMyPrivatDoctorCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *deptLb;
@property (nonatomic, strong) UILabel *hospLb;

@property (nonatomic, strong) UILabel *tagLb;
@property (nonatomic, strong) UILabel *descLb;

@property (nonatomic, strong) UILabel *ratioLb;
@property (nonatomic, strong) UILabel *stateLb;

@end

@implementation HEMyPrivatDoctorCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.qmui_borderPosition = QMUIViewBorderPositionTop;
        self.qmui_borderWidth = 0.5;
        self.qmui_borderColor = CSplitLineColor;
     
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
    
    warp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(0);
        make.right.equalTo(self.contentView).mas_offset(0);
        make.height.mas_greaterThanOrEqualTo(105);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
    
    // 商品图片
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];

    // 姓名
    _titleLb = [UILabel new];
    _titleLb.text = @"张三";
    _titleLb.font = DYBlodFont(18);
    [warp addSubview:_titleLb];

    // 科室
    _deptLb = [UILabel new];
    _deptLb.text = @"副主任医师 | 老年病科";
    _deptLb.font = DYFont(15);
    _deptLb.textColor = CNavSubTitleColor;
    [warp addSubview:_deptLb];

    // 所属医院
    _hospLb = [UILabel new];
    _hospLb.text = @"中南大学湘雅医院";
    _hospLb.font = DYFont(15);
    _hospLb.textColor = CNavLightBlackColor;
    [warp addSubview:_hospLb];

    // 标签   我的医生 \ 关注
    _tagLb = [UILabel new];
    _tagLb.text = @"私人医生";
    _tagLb.backgroundColor = KHexColor(@"F2791C");
    _tagLb.textColor = KWhiteColor;
    _tagLb.font = DYFont(13);
    _tagLb.textAlignment = NSTextAlignmentCenter;
    [warp addSubview:_tagLb];
    _tagLb.layer.cornerRadius = 3;
    _tagLb.layer.masksToBounds = YES;

    // 描述
    _descLb = [UILabel new];
    _descLb.text = @"中南大学湘雅医院中南大学湘雅医院中南大学湘雅医院中南大学湘雅医院中南大学湘雅医院中南大学湘雅医院";
    _descLb.font = DYFont(15);
    _descLb.textColor = CGrayColor;
    _descLb.numberOfLines = 2;
    [warp addSubview:_descLb];
    
    //  接诊率 好评率
    _ratioLb = [UILabel new];
    _ratioLb.text = @"接诊率:0%  好评率:0%";
    _ratioLb.font = DYBlodFont(15);
    _ratioLb.textColor = UIColor.blackColor;
    [warp addSubview:_ratioLb];
    
    
    //
    _stateLb = [UILabel new];
    _stateLb.text = @"￥0起";
    _stateLb.font = DYBlodFont(15);
    _stateLb.textColor = CNavBgColor;
    _stateLb.textAlignment = NSTextAlignmentRight;
    [warp addSubview:_stateLb];

    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(warp).mas_offset(15);
       make.left.equalTo(warp).mas_offset(15);
       make.width.height.mas_offset(72);
//       make.bottom.equalTo(warp.mas_bottom).mas_offset(-15);
    }];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 36;

    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(_goodsimgView.mas_top);
       make.left.equalTo(_goodsimgView.mas_right).mas_offset(11);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

    
    [_deptLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_titleLb.mas_bottom);
       make.left.equalTo(_titleLb.mas_right).mas_offset(10);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];
  
    [_hospLb mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(_titleLb.mas_bottom).mas_offset(5);
       make.left.equalTo(_titleLb.mas_left);
    }];
//    [_hospLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
   
    
    [_stateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_hospLb);
//        make.right.equalTo(_tagLb.mas_left).mas_offset(-10);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];
    [_stateLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

//    [_tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(_hospLb);
//        make.right.equalTo(warp.mas_right).mas_offset(-10);
//        make.width.mas_offset([@"私人医生" widthForFont:_tagLb.font] + 10);
//        make.height.mas_offset([@"私人医生" heightForFont:_tagLb.font width:[@"私人医生" widthForFont:_tagLb.font]] + 5);
//    }];


    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_hospLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
    }];

    [_ratioLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_descLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(warp.mas_right).mas_offset(-10);
        make.bottom.equalTo(warp).mas_offset(-15);
    }];
}

- (void)setModel:(HEDoctorInfoModel *)model {
    _model = model;
    
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage: IMAGE_NAMED(@"hmang")];
    
    _titleLb.text = model.realname;
    _deptLb.text = model.KDeptStr;
    _hospLb.text = model.hospital_name;
    _descLb.text = model.KSkilful;
    
    _stateLb.text = model.KUserDocState;
    _stateLb.textColor = model.KUserDocStateColor;
    _ratioLb.text = model.KRatio;
    
    [_stateLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(model.KPriceWidth);
    }]; 
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
